package com.oa.srms.apps.business.goods.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.oa.srms.apps.business.goods.IGoodCategoryService;
import com.oa.srms.apps.business.goods.IGoodReceivedService;
import com.oa.srms.apps.business.student.IStudentInfoService;
import com.oa.srms.apps.constants.IReceiveStates;
import com.oa.srms.apps.dao.goods.IGoodReceivedDao;
import com.oa.srms.apps.entity.goods.GoodReceivedValue;

public class GoodReceivedServiceImpl implements IGoodReceivedService {
	@Autowired
	private GoodReceivedValue goodReceivedValue;
	@Autowired
	private IStudentInfoService studentInfoService;
	@Autowired
	private IGoodCategoryService goodCategoryService;
	@Autowired
	private IGoodReceivedDao goodReceivedDao;

	@Override
	public Integer addGoodReceived(int studentId, int categoryId) throws Exception {
		goodReceivedValue.setStuInfo(studentInfoService.queryById(studentId));
		goodReceivedValue.setGoodCategory(goodCategoryService.quaryByCategoryId(categoryId));
		goodReceivedValue.setComments("暂无");
		goodReceivedValue.setStates(IReceiveStates.UNCLAIMED);
		return goodReceivedDao.addGoodReceived(goodReceivedValue);
	}

	@Override
	public void modifyGoodReceived(int id, String received, String comments) throws Exception {
		goodReceivedValue = this.queryById(id);
		if (goodReceivedValue != null) {
			goodReceivedValue.setReceived(received);
			goodReceivedValue.setComments(comments);
			goodReceivedDao.editGoodReceived(goodReceivedValue);
		}
	}

	@Override
	public GoodReceivedValue queryById(Integer id) throws Exception {
		return goodReceivedDao.queryById(id);
	}

	@Override
	public List<GoodReceivedValue> queryGoodReceived(String stuNo, Integer maxStates)
			throws Exception {
		return goodReceivedDao.queryGoodReceived(stuNo, maxStates);
	}

	@Override
	public void setPayStates(Integer id, Integer state) throws Exception {
		goodReceivedValue = this.queryById(id);
		if (goodReceivedValue != null) {
			goodReceivedValue.setStates(state);
			goodReceivedDao.editGoodReceived(goodReceivedValue);
		}
		
	}

}
